package io.terminus.paas.profiler.utils

/**
 * Created by gengrong on 16/3/16.
 *
 * @RegistryServerSync 中使用该类方法,直接从Dubbo中Copy部分引用到的方法
 */
object DubboTool {
    fun getInterface(serviceId: String): String {
        var service = serviceId
        if (service.length > 0) {
            var i = service.indexOf('/')
            if (i >= 0) {
                service = service.substring(i + 1)
            }
            i = service.lastIndexOf(':')
            if (i >= 0) {
                service = service.substring(0, i)
            }
        }
        return service
    }

    fun getGroup(service: String): String? {
        if (service.length > 0) {
            val i = service.indexOf('/')
            if (i >= 0) {
                return service.substring(0, i)
            }
        }
        return null
    }

    fun getVersion(service: String): String? {
        if (service.length > 0) {
            val i = service.lastIndexOf(':')
            if (i >= 0) {
                return service.substring(i + 1)
            }
        }
        return null
    }
}